/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.nc.kyiv.yellow.sociallibrary.reports;
/*
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.ss.util.WorkbookUtil;
*/
/**
 *
 * @author Виталий
 */
/*
public class BIReportXLSRenderer implements IReportRenderer {

    private String outputFileName;
    protected List<ReportNode> rootlist;
    protected ReportNode root;
    protected HSSFWorkbook reportWb;
    protected int gridStartRow = 0;

    public BIReportXLSRenderer(String outputFileName) {
        this.outputFileName = outputFileName;
    }

    public void render(List<ReportNode> reportRootList) throws ReportRenderingException {
        this.rootlist = reportRootList;
        this.root = reportRootList.get(0);
        reportWb = new HSSFWorkbook();
        // Converting name of root node, used as sheet name, to form safe for all xls viewers 
        root.setName(WorkbookUtil.createSafeSheetName(root.getName()));
        Sheet reportSheet = reportWb.createSheet(root.getName());

        List nodes;
        nodes = root.getChildByName("PageHeader");
        if (!nodes.isEmpty()) {
            renderPageHeader((ReportNode) nodes.get(0));
        }
        nodes = root.getChildByName("Title");
        if (!nodes.isEmpty()) {
            renderTitle((ReportNode) nodes.get(0));
        }
        nodes = root.getChildByName("BIGrid");
        if (!nodes.isEmpty()) {
            renderBIGrid((ReportNode) nodes.get(0));
        }
        nodes = root.getChildByName("PageFooter");
        if (!nodes.isEmpty()) {
            renderPageFooter((ReportNode) nodes.get(0));
        }
        try {
            writeReportWorkbook();
        } catch (IOException ex) {
            throw new ReportRenderingException("Error when writing report to file \""
                    + outputFileName + "\"",
                    ex);
        }
    }

    protected void renderPageHeader(ReportNode pageHeader) {
        Header pageHead = reportWb.getSheet(root.getName()).getHeader();
        String headerText = "";
        Object attribute;
        attribute = pageHeader.getAttribute("datetime");
        if (attribute instanceof Date) {
            headerText = "Report generated " + (new SimpleDateFormat("yyyy-MM-dd HH:mm")).format((Date) attribute);
        }
        pageHead.setLeft(headerText);
    }

    protected void renderTitle(ReportNode title) {
        Sheet reportSheet = reportWb.getSheet(root.getName());
        Row titleRow = reportSheet.createRow(gridStartRow);
        gridStartRow += 2;
        Font titleFont = reportWb.createFont();
        titleFont.setFontName("Calibri");
        titleFont.setFontHeightInPoints((short) 20);
        CellStyle titleCellStyle = reportWb.createCellStyle();
        titleCellStyle.setFont(titleFont);
        titleCellStyle.setAlignment(CellStyle.ALIGN_CENTER);
        Cell titleCell = titleRow.createCell(0);
        titleCell.setCellStyle(titleCellStyle);
        Object attribute;
        attribute = title.getAttribute("text");
        if (attribute != null) {
            titleCell.setCellValue(attribute.toString());
        }
        reportSheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 7));

        titleRow = reportSheet.createRow(gridStartRow);
        gridStartRow += 2;
        titleCell = titleRow.createCell(0);
        titleCell.setCellValue("Publication date:");
        titleCell = titleRow.createCell(1);
        attribute = title.getAttribute("pubdate");
        if (attribute != null) {
            titleCell.setCellValue((new SimpleDateFormat("dd-MM-yyyy")).format((Date) attribute));
        }
    }

    protected void renderTableTitle() {
        Sheet reportSheet = reportWb.getSheet(root.getName());
        Row tableTitleRow = reportSheet.createRow(gridStartRow);
        Cell tableTitleCells[] = new Cell[8];
        Font tableTitleFont = reportWb.createFont();
        tableTitleFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
        tableTitleFont.setItalic(true);
        CellStyle tableTitleCellStyle = reportWb.createCellStyle();
        tableTitleCellStyle.setFont(tableTitleFont);
        tableTitleCellStyle.setAlignment(CellStyle.ALIGN_CENTER);
        tableTitleCellStyle.setBorderBottom(CellStyle.BORDER_THIN);
        tableTitleCellStyle.setBottomBorderColor(IndexedColors.BLACK.getIndex());
        tableTitleCellStyle.setBorderLeft(CellStyle.BORDER_THIN);
        tableTitleCellStyle.setLeftBorderColor(IndexedColors.BLACK.getIndex());
        tableTitleCellStyle.setBorderRight(CellStyle.BORDER_THIN);
        tableTitleCellStyle.setRightBorderColor(IndexedColors.BLACK.getIndex());
        tableTitleCellStyle.setBorderTop(CellStyle.BORDER_THIN);
        tableTitleCellStyle.setTopBorderColor(IndexedColors.BLACK.getIndex());
        for (int i = 0; i < tableTitleCells.length; i++) {
            tableTitleCells[i] = tableTitleRow.createCell(i);
            tableTitleCells[i].setCellStyle(tableTitleCellStyle);
        }
        tableTitleCells[0].setCellValue("ISBN");
        tableTitleCells[1].setCellValue("Title");
        tableTitleCells[2].setCellValue("Author");
        tableTitleCells[3].setCellValue("Genre");
        tableTitleCells[4].setCellValue("Pages");
        tableTitleCells[5].setCellValue("Rating");
        tableTitleCells[6].setCellValue("Date of Publishing");
        tableTitleCells[7].setCellValue("Publisher");
        gridStartRow++;
    }

    protected void renderBIGrid(ReportNode grid) {
        renderTableTitle();
        List nodes;
        nodes = grid.getChildByName("BIGridRow");
        if (!nodes.isEmpty()) {
            for (int i = 0; i < nodes.size(); i++) {
                renderBIGridRow((ReportNode) nodes.get(i), i);
            }
        }
    }

    protected void renderBIGridRow(ReportNode row, int index) {
        Sheet reportSheet = reportWb.getSheet(root.getName());
        Row biRow = reportSheet.createRow(gridStartRow + index);

        Cell infoCells[] = new Cell[8];
        CellStyle infoCellStyle = reportWb.createCellStyle();
        infoCellStyle.setBorderBottom(CellStyle.BORDER_THIN);
        infoCellStyle.setBottomBorderColor(IndexedColors.BLACK.getIndex());
        infoCellStyle.setBorderLeft(CellStyle.BORDER_THIN);
        infoCellStyle.setLeftBorderColor(IndexedColors.BLACK.getIndex());
        infoCellStyle.setBorderRight(CellStyle.BORDER_THIN);
        infoCellStyle.setRightBorderColor(IndexedColors.BLACK.getIndex());
        infoCellStyle.setBorderTop(CellStyle.BORDER_THIN);
        infoCellStyle.setTopBorderColor(IndexedColors.BLACK.getIndex());
        for (int i = 0; i < infoCells.length; i++) {
            infoCells[i] = biRow.createCell(i);
            infoCells[i].setCellStyle(infoCellStyle);

        }
        Object attribute;
        attribute = row.getAttribute("isbn");
        if (attribute != null) {
            infoCells[0].setCellValue(attribute.toString());
        }
        attribute = row.getAttribute("title");
        if (attribute != null) {
            infoCells[1].setCellValue(attribute.toString());
        }
        attribute = row.getAttribute("author");
        if (attribute != null) {
            infoCells[2].setCellValue(attribute.toString());
        }
        attribute = row.getAttribute("genre");
        if (attribute != null) {
            infoCells[3].setCellValue(attribute.toString());
        }
        attribute = row.getAttribute("pages");
        if (attribute != null) {
            infoCells[4].setCellValue(attribute.toString());
        }
        attribute = row.getAttribute("rating");
        if (attribute != null) {
            infoCells[5].setCellValue(attribute.toString());
        }
        attribute = row.getAttribute("pubdate");
        if (attribute instanceof Date) {
            infoCells[6].setCellValue((new SimpleDateFormat("dd-MM-yyyy")).format((Date) attribute));
        }
        attribute = row.getAttribute("publisher");
        if (attribute != null) {
            infoCells[7].setCellValue(attribute.toString());
        }
        reportSheet.autoSizeColumn(0);
        reportSheet.autoSizeColumn(1);
        reportSheet.autoSizeColumn(2);
        reportSheet.autoSizeColumn(3);
        reportSheet.autoSizeColumn(4);
        reportSheet.autoSizeColumn(5);
        reportSheet.autoSizeColumn(6);
        reportSheet.autoSizeColumn(7);

    }

    protected void renderPageFooter(ReportNode pageFooter) {
        // No footer need in this document
    }

    protected void writeReportWorkbook() throws FileNotFoundException, IOException {
        FileOutputStream fileOut = new FileOutputStream(outputFileName);
        reportWb.write(fileOut);
        fileOut.close();
    }
}
*/